Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
.innerHTML -> console.log shows formatting but DOM element doesn't
        let parser = new DOMParser();
        let OFPXML = parser.parseFromString(json, "application/xml");
        Formats = OFPXML.querySelector('Formats');
        XML1 = Formats.children[1].innerHTML;
        console.log(XML1); // This retains linebreaks
        document.getElementById('text_from_XML_node_here').innerHTML = XML1;  // This does not retain them.

Console.log shows the text with linebreaks but the DOM element removed them all.

This is a low-priority question as I am just learning and experimenting with things.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The line breaks are not shown in the rendered HTML element. When DOM elements are rendered, raw newlines like \n are ignored. If you want line breaks explicitly to show, you have the following options:

  • Change the element to a <pre>
  • Replace newlines in your XML1 variable with <br />
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda